package com.gavindon.android.adapters

import android.graphics.Color
import androidx.core.content.ContextCompat
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.gavindon.android.R
import com.gavindon.android.base.INTENT_COURSE_ID
import com.gavindon.android.base.INTENT_COURSE_NAME
import com.gavindon.android.base.INTENT_PACKAGE_ID
import com.gavindon.android.entity.CourseOutputDTO
import com.gavindon.android.entity.PackageOutputDTO
import com.gavindon.android.network.BASE_URL_IMG
import com.gavindon.android.view.combo.ComboLstActivity
import com.gavindon.android.view.video.VideoDetailActivity
import com.gavindon.android.widget.FocusViewUtils
import org.jetbrains.anko.startActivity

/**
 * description:订单adapter
 * Created by liNan on  2022-3-8 21:52
 */
//课程订单
class CourseOrderAdapter(layoutResId: Int, data: MutableList<CourseOutputDTO>?) :
    BaseQuickAdapter<CourseOutputDTO, BaseViewHolder>(layoutResId, data) {
    override fun convert(holder: BaseViewHolder, item: CourseOutputDTO) {
        val showTime: String
        val color: Int
        if (item.validity == 1) {
            showTime = "已到期,去购买"
            color = ContextCompat.getColor(this.context, R.color.bottom10)
        } else {
            showTime = "到期时间:${item.validityEndTime}"
            color = Color.WHITE
        }
        holder.setText(R.id.ada_tv_name, item.courseName)
            .setText(R.id.ada_order_price, "￥${item.presentPrice}")
            .setText(R.id.ada_tv_order_category, "课程")
            .setText(R.id.ada_tv_order_time2, showTime)
            .setTextColor(R.id.ada_tv_order_time2, color)
            .setBackgroundResource(R.id.ada_csl_title, R.drawable.course_order_bg)
        Glide.with(holder.itemView).load("$BASE_URL_IMG/${item.file.fileUrl}")
            .into(holder.getView(R.id.ada_iv_order))
        FocusViewUtils.scaleView(holder.itemView, 0)
        holder.itemView.setOnClickListener {
            this.context.startActivity<VideoDetailActivity>(
                Pair(
                    INTENT_COURSE_ID,
                    item.courseId
                ),
                Pair(
                    INTENT_COURSE_NAME,
                    item.courseName
                ),
            )
        }
    }
}

//套餐订单
class ComboOrderAdapter(layoutResId: Int, data: MutableList<PackageOutputDTO>?) :
    BaseQuickAdapter<PackageOutputDTO, BaseViewHolder>(layoutResId, data) {
    override fun convert(holder: BaseViewHolder, item: PackageOutputDTO) {


        val showTime: String
        val color: Int
        if (item.validity == 1) {
            showTime = "已到期,去购买"
            color = ContextCompat.getColor(this.context, R.color.bottom10)
        } else {
            showTime = "到期时间:${item.validityEnTime}"
            color = Color.WHITE
        }

        holder.setText(R.id.ada_tv_name, item.packageName)
            .setText(R.id.ada_order_price, "￥${item.presentPrice}")
            .setText(R.id.ada_tv_order_category, "套餐")
            .setText(R.id.ada_tv_order_time2, showTime)
            .setTextColor(R.id.ada_tv_order_time2, color)
            .setBackgroundResource(R.id.ada_csl_title, R.drawable.combo_order_bg)
        Glide.with(holder.itemView).load("$BASE_URL_IMG/${item.file.fileUrl}")
            .into(holder.getView(R.id.ada_iv_order))
        FocusViewUtils.scaleView(holder.itemView, 0)

        holder.itemView.setOnClickListener {
            this.context.startActivity<ComboLstActivity>(
                Pair(INTENT_PACKAGE_ID, item.packageId),
            )
        }
    }
}